package com.clip.util;

import java.util.ResourceBundle;
/**
 * ��ȡ�����ļ��е��ַ�
 * @author Administrator
 *
 */
public class ResourceUtils {
	private static ResourceBundle getResource(String propertiesNm){
		return ResourceBundle.getBundle(propertiesNm);
	}
	public static String getString(String key,String propertiesName){
		return ResourceUtils.getResource(propertiesName).getString(key);
	}
	public static String getString(String key){
		return getString(key,"systemConfig");
	}
	/**
	 * 格式化文件size
	 * */
	public static String formatFileSize(Object size){
		double sizeb=0;
		if(size instanceof Integer){
			sizeb = (Integer)size;
		}else if(size instanceof Long){
			sizeb = (Long)size;
		}
		if((sizeb/1024)>1){
			if(((sizeb/1024)/1024)>1){
				double sizemb = (sizeb/1024)/1024;  
				sizemb=roundDouble(sizemb,1);
				//System.out.println(sizemb+"MB");
				return sizemb+"MB";
			}else{
				double sizekb = sizeb/1024;
				sizekb=roundDouble(sizekb,1);
				//System.out.println(sizekb+"KB");
				return sizekb+"KB";
			}
		}else{
			//System.out.println(sizeb+"B");
			return sizeb+"B";
		}
	}
	
	
	/**
	 * 保留两位小数（四舍五入）
	 * @param val 处理的值
	 * @param precision 小数的位数
	 * */
	public static double roundDouble(double val, int precision) {
        Double ret = null;   
        try {   
            double factor = Math.pow(10, precision);   
            ret = Math.floor(val * factor + 0.5) / factor;   
        } catch (Exception e) {
            e.printStackTrace();   
        }   
  
        return ret;   
    }
}
